package com.fancy.learncenter.ui.activity;

import android.content.Intent;
import android.os.Bundle;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.support.v7.widget.Toolbar;
import android.widget.ImageView;

import com.fancy.learncenter.R;
import com.fancy.learncenter.bean.BaseBean;
import com.fancy.learncenter.bean.ListenSpeakListDataBean;
import com.fancy.learncenter.common.MyApplication;
import com.fancy.learncenter.net.CustomNetCallBack;
import com.fancy.learncenter.net.CustomNetSubscriber;
import com.fancy.learncenter.net.HttpMehtod;
import com.fancy.learncenter.ui.activity.base.BaseActivity;
import com.fancy.learncenter.ui.adapter.EverydayListenSpeekAdapter;
import com.fancy.learncenter.utils.FileUtils;
import com.fancy.learncenter.utils.NetUtil;
import com.fancy.learncenter.utils.Utils;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import butterknife.Bind;
import butterknife.ButterKnife;
import butterknife.OnClick;
import okhttp3.ResponseBody;
import retrofit2.Response;

public class CartoonExpandTrainListActivity extends BaseActivity {

    @Bind(R.id.back)
    ImageView back;
    @Bind(R.id.toolbar)
    Toolbar toolbar;
    @Bind(R.id.recyclerView)
    RecyclerView recyclerView;
    List<ListenSpeakListDataBean.ResultBean> list;
    EverydayListenSpeekAdapter everydayListenSpeekAdapter;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setCartoonContentView(R.layout.activity_cartoon_read_list, Status.STATUS);
        ButterKnife.bind(this);
        initView();

        getList();
    }

    private void initView() {
        list = new ArrayList<>();
        LinearLayoutManager manager = new LinearLayoutManager(this);
        manager.setOrientation(LinearLayoutManager.VERTICAL);
        recyclerView.setLayoutManager(manager);

        everydayListenSpeekAdapter = new EverydayListenSpeekAdapter(this, list, FileUtils.getExpandRecorderAudioPath());
        recyclerView.setAdapter(everydayListenSpeekAdapter);

    }


    private void getList() {
        Map map = new HashMap();
        map.put("type", "2");
        map.put("classId", MyApplication.classIDStr);
        HttpMehtod.getInstance().listSpeakPackage(map, new CustomNetSubscriber(this) {
            @Override
            public void onNext(Response<ResponseBody> responseBodyResponse) {

                BaseBean<ListenSpeakListDataBean> baseBean = Utils.fromJsonObject(NetUtil.getResResult(responseBodyResponse), ListenSpeakListDataBean.class);
                //数据业务逻辑处理
                CustomNetCallBack callBack = new CustomNetCallBack(getContext(), baseBean);
                callBack.setCallBack(new CustomNetCallBack.NetCallBack<ListenSpeakListDataBean>() {

                    @Override
                    public void success(ListenSpeakListDataBean dataBean) {
                        everydayListenSpeekAdapter.addAll(dataBean.getResult());
                    }

                    @Override
                    public void fail(String errorCode) {
                    }
                }).dealData();

            }
        });
    }
}
